package at.fhooe.generator;

import at.fhooe.agaeScriptDsl.BusinessLogic;
import at.fhooe.agaeScriptDsl.Button;
import at.fhooe.agaeScriptDsl.GuiItem;
import at.fhooe.agaeScriptDsl.HandlerItem;
import at.fhooe.agaeScriptDsl.Label;
import at.fhooe.agaeScriptDsl.Screen;
import at.fhooe.agaeScriptDsl.TextField;
import com.google.common.collect.Iterables;
import javax.inject.Inject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;

@SuppressWarnings("all")
public class AgaeScriptDslGenerator implements IGenerator {
  @Inject
  private IQualifiedNameProvider _iQualifiedNameProvider;
  
  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    TreeIterator<EObject> _allContents = resource.getAllContents();
    Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
    Iterable<Screen> _filter = Iterables.<Screen>filter(_iterable, Screen.class);
    for (final Screen e : _filter) {
      QualifiedName _fullyQualifiedName = this._iQualifiedNameProvider.getFullyQualifiedName(e);
      String _string = _fullyQualifiedName.toString("/");
      String _plus = (_string + ".xml");
      CharSequence _compile = this.compile(e);
      fsa.generateFile(_plus, _compile);
    }
    TreeIterator<EObject> _allContents_1 = resource.getAllContents();
    Iterable<EObject> _iterable_1 = IteratorExtensions.<EObject>toIterable(_allContents_1);
    Iterable<Screen> _filter_1 = Iterables.<Screen>filter(_iterable_1, Screen.class);
    for (final Screen e_1 : _filter_1) {
      QualifiedName _fullyQualifiedName_1 = this._iQualifiedNameProvider.getFullyQualifiedName(e_1);
      String _string_1 = _fullyQualifiedName_1.toString("/");
      String _plus_1 = (_string_1 + ".jsp");
      CharSequence _compileGAE = this.compileGAE(e_1);
      fsa.generateFile(_plus_1, _compileGAE);
    }
    TreeIterator<EObject> _allContents_2 = resource.getAllContents();
    Iterable<EObject> _iterable_2 = IteratorExtensions.<EObject>toIterable(_allContents_2);
    Iterable<BusinessLogic> _filter_2 = Iterables.<BusinessLogic>filter(_iterable_2, BusinessLogic.class);
    for (final BusinessLogic e_2 : _filter_2) {
      CharSequence _compile_1 = this.compile(e_2);
      fsa.generateFile(
        "AndroidManifest.xml", _compile_1);
    }
    TreeIterator<EObject> _allContents_3 = resource.getAllContents();
    Iterable<EObject> _iterable_3 = IteratorExtensions.<EObject>toIterable(_allContents_3);
    Iterable<BusinessLogic> _filter_3 = Iterables.<BusinessLogic>filter(_iterable_3, BusinessLogic.class);
    for (final BusinessLogic e_3 : _filter_3) {
      CharSequence _compileGAE_1 = this.compileGAE(e_3);
      fsa.generateFile(
        "web.xml", _compileGAE_1);
    }
    TreeIterator<EObject> _allContents_4 = resource.getAllContents();
    Iterable<EObject> _iterable_4 = IteratorExtensions.<EObject>toIterable(_allContents_4);
    Iterable<BusinessLogic> _filter_4 = Iterables.<BusinessLogic>filter(_iterable_4, BusinessLogic.class);
    for (final BusinessLogic e_4 : _filter_4) {
      QualifiedName _fullyQualifiedName_2 = this._iQualifiedNameProvider.getFullyQualifiedName(e_4);
      String _string_2 = _fullyQualifiedName_2.toString("/");
      String _plus_2 = (_string_2 + ".java");
      CharSequence _compileBL = this.compileBL(e_4);
      fsa.generateFile(_plus_2, _compileBL);
    }
    TreeIterator<EObject> _allContents_5 = resource.getAllContents();
    Iterable<EObject> _iterable_5 = IteratorExtensions.<EObject>toIterable(_allContents_5);
    Iterable<BusinessLogic> _filter_5 = Iterables.<BusinessLogic>filter(_iterable_5, BusinessLogic.class);
    for (final BusinessLogic e_5 : _filter_5) {
      QualifiedName _fullyQualifiedName_3 = this._iQualifiedNameProvider.getFullyQualifiedName(e_5);
      String _string_3 = _fullyQualifiedName_3.toString("/");
      String _plus_3 = (_string_3 + "Servlet.java");
      CharSequence _compileGAEBL = this.compileGAEBL(e_5);
      fsa.generateFile(_plus_3, _compileGAEBL);
    }
  }
  
  public CharSequence compile(final Screen s) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("\t");
    _builder.append("<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("android:orientation=\"vertical\"");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("android:layout_width=\"fill_parent\"");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("android:layout_height=\"fill_parent\"");
    _builder.newLine();
    _builder.append("              ");
    _builder.append("android:background=\"#CAE1FF\"");
    _builder.newLine();
    _builder.append("        ");
    _builder.append(">");
    _builder.newLine();
    {
      EList<GuiItem> _guiItems = s.getGuiItems();
      for(final GuiItem item : _guiItems) {
        {
          if ((item instanceof Button)) {
            final Button b = ((Button) item);
            _builder.newLineIfNotEmpty();
            CharSequence _compile = this.compile(b);
            _builder.append(_compile, "");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          if ((item instanceof Label)) {
            final Label l = ((Label) item);
            _builder.newLineIfNotEmpty();
            CharSequence _compile_1 = this.compile(l);
            _builder.append(_compile_1, "");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          if ((item instanceof TextField)) {
            final TextField t = ((TextField) item);
            _builder.newLineIfNotEmpty();
            CharSequence _compile_2 = this.compile(t);
            _builder.append(_compile_2, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.newLine();
    _builder.append("</LinearLayout>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence compileGAE(final Screen s) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<%@ page contentType=\"text/html;charset=UTF-8\" language=\"java\" %>");
    _builder.newLine();
    _builder.append("<%@ page import=\"java.util.List\" %>");
    _builder.newLine();
    _builder.append("<%@ page import=\"com.google.appengine.api.users.User\" %>");
    _builder.newLine();
    _builder.append("<%@ page import=\"com.google.appengine.api.users.UserService\" %>");
    _builder.newLine();
    _builder.append("<%@ page import=\"com.google.appengine.api.users.UserServiceFactory\" %>");
    _builder.newLine();
    _builder.append("<%@ taglib prefix=\"fn\" uri=\"http://java.sun.com/jsp/jstl/functions\" %>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("<html>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<body>");
    _builder.newLine();
    {
      EList<GuiItem> _guiItems = s.getGuiItems();
      for(final GuiItem item : _guiItems) {
        {
          if ((item instanceof Label)) {
            final Label l = ((Label) item);
            _builder.newLineIfNotEmpty();
            CharSequence _compileGAE = this.compileGAE(l);
            _builder.append(_compileGAE, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("  \t");
    _builder.newLine();
    _builder.append("  \t");
    _builder.append("<% if (request.getParameter(\"username\") != null) { %>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("<%= request.getParameter(\"username\")%>");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("<% } %>");
    _builder.newLine();
    {
      EList<GuiItem> _guiItems_1 = s.getGuiItems();
      for(final GuiItem item_1 : _guiItems_1) {
        {
          if ((item_1 instanceof Button)) {
            final Button b = ((Button) item_1);
            _builder.newLineIfNotEmpty();
            CharSequence _compileGAEAction = this.compileGAEAction(b);
            _builder.append(_compileGAEAction, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("\t");
    _builder.newLine();
    {
      EList<GuiItem> _guiItems_2 = s.getGuiItems();
      for(final GuiItem item_2 : _guiItems_2) {
        {
          if ((item_2 instanceof TextField)) {
            _builder.append("\t\t");
            final TextField t = ((TextField) item_2);
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            CharSequence _compileGAE_1 = this.compileGAE(t);
            _builder.append(_compileGAE_1, "		");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("\t    ");
    _builder.newLine();
    {
      EList<GuiItem> _guiItems_3 = s.getGuiItems();
      for(final GuiItem item_3 : _guiItems_3) {
        {
          if ((item_3 instanceof Button)) {
            final Button b_1 = ((Button) item_3);
            _builder.newLineIfNotEmpty();
            CharSequence _compileGAE_2 = this.compileGAE(b_1);
            _builder.append(_compileGAE_2, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("\t    ");
    _builder.newLine();
    _builder.append("  \t");
    _builder.append("</form>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("  ");
    _builder.append("</body>");
    _builder.newLine();
    _builder.append("</html>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence compile(final Button b) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<Button");
    _builder.newLine();
    _builder.append("\t            ");
    _builder.append("android:layout_width=\"wrap_content\"");
    _builder.newLine();
    _builder.append("\t            ");
    _builder.append("android:layout_height=\"wrap_content\"");
    _builder.newLine();
    _builder.append("\t            ");
    _builder.append("android:text=\"");
    String _buttonText = b.getButtonText();
    _builder.append(_buttonText, "	            ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t            ");
    _builder.append("android:id=\"@+id/");
    String _name = b.getName();
    _builder.append(_name, "	            ");
    _builder.append("\" android:layout_gravity=\"left|center_vertical\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t            ");
    _builder.append("android:onClick=\"");
    String _btnHandlerName = b.getBtnHandlerName();
    _builder.append(_btnHandlerName, "	            ");
    _builder.append("\"/>");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compileGAE(final Button b) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<div><input type=\"submit\" value=\"");
    String _buttonText = b.getButtonText();
    _builder.append(_buttonText, "");
    _builder.append("\" /></div>");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compileGAEAction(final Button b) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<form action=\"/");
    String _btnHandlerName = b.getBtnHandlerName();
    _builder.append(_btnHandlerName, "");
    _builder.append("\" method=\"post\">");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compile(final Label l) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<TextView");
    _builder.newLine();
    _builder.append("            \t");
    _builder.append("android:layout_width=\"fill_parent\"");
    _builder.newLine();
    _builder.append("            \t");
    _builder.append("android:layout_height=\"wrap_content\"");
    _builder.newLine();
    _builder.append("           \t \t");
    _builder.append("android:text=\"");
    String _labelText = l.getLabelText();
    _builder.append(_labelText, "           	 	");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("            \t");
    _builder.append("android:id=\"@+id/");
    String _name = l.getName();
    _builder.append(_name, "            	");
    _builder.append("\"/>");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compileGAE(final Label l) {
    StringConcatenation _builder = new StringConcatenation();
    String _labelText = l.getLabelText();
    _builder.append(_labelText, "");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compile(final TextField t) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<EditText");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("android:layout_width=\"fill_parent\"");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("android:layout_height=\"wrap_content\"");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("android:id=\"@+id/");
    String _name = t.getName();
    _builder.append(_name, "        ");
    _builder.append("\" android:layout_gravity=\"left|center_vertical\"/>");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compileGAE(final TextField t) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<div><textarea name=\"");
    String _name = t.getName();
    _builder.append(_name, "");
    _builder.append("\" rows=\"3\" cols=\"60\">");
    String _textFieldText = t.getTextFieldText();
    _builder.append(_textFieldText, "");
    _builder.append("</textarea></div>");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  public CharSequence compile(final BusinessLogic bl) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    _builder.newLine();
    _builder.append("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"");
    _builder.newLine();
    _builder.append("          ");
    _builder.append("package=\"com.guestbook\"");
    _builder.newLine();
    _builder.append("          ");
    _builder.append("android:versionCode=\"1\"");
    _builder.newLine();
    _builder.append("          ");
    _builder.append("android:versionName=\"1.0\">");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<uses-sdk android:minSdkVersion=\"8\"/>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<application android:label=\"@string/app_name\" android:icon=\"@drawable/ic_launcher\">");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("<activity android:name=\"");
    String _name = bl.getName();
    _builder.append(_name, "        ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("                  ");
    _builder.append("android:label=\"@string/app_name\">");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("<intent-filter>");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("<action android:name=\"android.intent.action.MAIN\"/>");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("<category android:name=\"android.intent.category.LAUNCHER\"/>");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("</intent-filter>");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("</activity>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("</application>");
    _builder.newLine();
    _builder.append("</manifest>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence compileGAE(final BusinessLogic bl) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><web-app xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"2.5\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee                http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\">");
    _builder.newLine();
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<!-- Servlets -->");
    _builder.newLine();
    {
      EList<HandlerItem> _handlerItems = bl.getHandlerItems();
      for(final HandlerItem item : _handlerItems) {
        _builder.append("\t\t  \t");
        _builder.append("<servlet>");
        _builder.newLine();
        _builder.append("<servlet-name>");
        String _name = item.getName();
        _builder.append(_name, "");
        _builder.append("</servlet-name>");
        _builder.newLineIfNotEmpty();
        _builder.append("<servlet-class>");
        String _name_1 = bl.getName();
        _builder.append(_name_1, "");
        _builder.append("Servlet</servlet-class>");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t  \t");
        _builder.append("</servlet>");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("<servlet-mapping>");
        _builder.newLine();
        _builder.append("\t\t    \t");
        _builder.append("<servlet-name>");
        String _name_2 = item.getName();
        _builder.append(_name_2, "		    	");
        _builder.append("</servlet-name>");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t    \t");
        _builder.append("<url-pattern>/");
        String _name_3 = item.getName();
        _builder.append(_name_3, "		    	");
        _builder.append("</url-pattern>");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t  \t");
        _builder.append("</servlet-mapping>");
        _builder.newLine();
      }
    }
    _builder.append("  ");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<!-- Default page to serve -->");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<welcome-file-list>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<welcome-file>");
    String _layoutName = bl.getLayoutName();
    _builder.append(_layoutName, "    ");
    _builder.append(".jsp</welcome-file>");
    _builder.newLineIfNotEmpty();
    _builder.append("  ");
    _builder.append("</welcome-file-list>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<servlet>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<servlet-name>SystemServiceServlet</servlet-name>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<init-param>");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("<param-name>services</param-name>");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("<param-value/>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("</init-param>");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("</servlet>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("  ");
    _builder.append("<servlet-mapping>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<servlet-name>SystemServiceServlet</servlet-name>");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("<url-pattern>/_ah/spi/*</url-pattern>");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("</servlet-mapping>");
    _builder.newLine();
    _builder.newLine();
    _builder.append("</web-app>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence compileBL(final BusinessLogic logic) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import android.app.Activity;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("import android.os.Bundle;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("import android.view.View;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("import android.widget.EditText;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("import android.widget.TextView;");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public class ");
    String _name = logic.getName();
    _builder.append(_name, "	");
    _builder.append(" extends Activity {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void onCreate(Bundle savedInstanceState) {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("super.onCreate(savedInstanceState);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("setContentView(R.layout.");
    String _layoutName = logic.getLayoutName();
    _builder.append(_layoutName, "	");
    _builder.append(");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    {
      EList<HandlerItem> _handlerItems = logic.getHandlerItems();
      for(final HandlerItem item : _handlerItems) {
        _builder.append(" ");
        _builder.append("public void ");
        String _name_1 = item.getName();
        _builder.append(_name_1, " ");
        _builder.append("(View v){");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("\t");
        _builder.append("EditText msgContent = (EditText) findViewById(R.id.");
        String _componentFromName = item.getComponentFromName();
        _builder.append(_componentFromName, " 	");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("\t");
        _builder.append("TextView msgDisplay = (TextView) findViewById(R.id.");
        String _componentToName = item.getComponentToName();
        _builder.append(_componentToName, " 	");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
        _builder.append(" ");
        _builder.append("\t");
        _builder.append("String msgText = msgContent.getText().toString();");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("\t");
        _builder.append("msgDisplay.setText(\"Hello, \"+msgText);");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.newLine();
    _builder.append("} ");
    return _builder;
  }
  
  public CharSequence compileGAEBL(final BusinessLogic logic) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import java.io.IOException;");
    _builder.newLine();
    _builder.append("import java.io.PrintWriter;");
    _builder.newLine();
    _builder.append("import javax.servlet.ServletException;");
    _builder.newLine();
    _builder.append("import javax.servlet.http.*;");
    _builder.newLine();
    _builder.append("import java.util.logging.Logger;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _name = logic.getName();
    _builder.append(_name, "");
    _builder.append(" extends HttpServlet {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static final long serialVersionUID = 1L;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static final Logger log = Logger.getLogger(");
    String _name_1 = logic.getName();
    _builder.append(_name_1, "	");
    _builder.append(".class.getName());");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected void doGet(HttpServletRequest req,");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("HttpServletResponse resp) throws ServletException, IOException {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("resp.sendRedirect(\"/");
    String _layoutName = logic.getLayoutName();
    _builder.append(_layoutName, "		");
    _builder.append(".jsp\");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public void doPost(HttpServletRequest req, HttpServletResponse resp)");
    _builder.newLine();
    _builder.append("                ");
    _builder.append("throws IOException {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("PrintWriter out = resp.getWriter();");
    _builder.newLine();
    {
      EList<HandlerItem> _handlerItems = logic.getHandlerItems();
      for(final HandlerItem item : _handlerItems) {
        _builder.append("String ");
        String _componentFromName = item.getComponentFromName();
        _builder.append(_componentFromName, "");
        _builder.append(" = req.getParameter(\"");
        String _componentFromName_1 = item.getComponentFromName();
        _builder.append(_componentFromName_1, "");
        _builder.append("\");");
        _builder.newLineIfNotEmpty();
        _builder.append("log.info(\"Greeting posted: \" + ");
        String _componentFromName_2 = item.getComponentFromName();
        _builder.append(_componentFromName_2, "");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t        \t");
        _builder.append("resp.sendRedirect(\"/");
        String _layoutName_1 = logic.getLayoutName();
        _builder.append(_layoutName_1, "		        	");
        _builder.append(".jsp?username=\"+");
        String _componentFromName_3 = item.getComponentFromName();
        _builder.append(_componentFromName_3, "		        	");
        _builder.append(");");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}
